// import { Context } from "egg";

/*
 * @copyright: Huang Ding
 * @Author: ding-cx
 * @Date: 2020-12-12 17:40:20
 * @LastEditors: ding-cx
 * @LastEditTime: 2021-12-06 09:31:25
 * @Description: egg扩展，扩展context对象
 */

import { IResponseBodyData } from "egg";
import * as util from "util";

export default {
	throw(msg: string, ...args: any[]) {
		msg = util.format(msg, ...args);
		const e: any = new Error(`Error: ${msg}`);
		e.isDineggBizError = true;
		throw e;
	},
	success(data: any, code?: number, msg?: string) {
		const sendData: IResponseBodyData = {
			code: code || 20000,
			data,
			msg: msg || "success",
		};
		throw { sendData, message: msg || "success", isDineggBizSuccess: true };
	},
	error(msg: string, code?: number, msgDetails?: string[]) {
		const sendData: IResponseBodyData = {
			code: code || 50000,
			data: null,
			msg: msg,
			details: msgDetails || [],
		};
		throw { sendData, message: msg, isDineggBizSuccess: true };
	},
};
